<template>
    <div class="app-container">
       <el-form :model="queryParams" ref="queryRef" v-show="showSearch" :inline="true" label-width="90px">
          <el-form-item label="用户昵称：" prop="nickname">
             <el-input
                v-model="queryParams.nickname"
                placeholder="请输入"
                clearable
                style="width: 240px"
                @keyup.enter="handleQuery"
             />
          </el-form-item>
          <el-form-item label="用户ID：" prop="userID">
             <el-input
                v-model="queryParams.userID"
                placeholder="请输入"
                clearable
                style="width: 240px"
                @keyup.enter="handleQuery"
             />
          </el-form-item>
          <el-form-item>
             <el-button icon="Refresh" @click="resetQuery">重置</el-button>
             <el-button type="primary" icon="Search" @click="handleQuery">查询</el-button>
          </el-form-item>
       </el-form>
       <el-row :gutter="10" class="mb8">
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
       </el-row>
       <!-- 表格数据 -->
       <el-table v-loading="loading" :data="roleList">
        <el-table-column label="" prop="roleId" width="100">
              <template #default="scope">
                <span class="idx"  :style="{ backgroundColor: scope.$index < 3 ? 'black' : 'gray' }">
                  {{scope.$index + 1}}
                </span>
              </template>
          </el-table-column>
          <el-table-column label="用户头像" prop="faceURL" width="100">
            <template #default="scope">
              <span class="avatar" v-if="scope.row.faceURL === ''">
                  {{scope.row.nickname[0]}}
              </span>
              <div v-else>
                <img :src="scope.row.faceURL" alt="light" />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="用户呢称" prop="nickname" :show-overflow-tooltip="true" />
          <el-table-column label="用户ID" prop="userID" />
          <el-table-column label="在线状态" prop="account">
             <template #default="scope">
                  {{scope.row.account === "" ? '-' : scope.row.account}}
             </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
             <template #default="scope">
                 <el-button link type="primary"  @click="handleUpdate(scope.row)" disabled>强制下线</el-button>
                 <el-button link type="primary"  @click="handleRelation(scope.row)">关系链</el-button>
             </template>
          </el-table-column>
       </el-table>
 
       <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="pageObj.pageNumber"
          v-model:limit="pageObj.showNumber"
          @pagination="getList"
       />
    </div>
 </template>
 
 <script setup name="Role">
 import { getUserList } from "@/api/im/user";
 import { ref } from "vue";
 
 const router = useRouter();
 const { proxy } = getCurrentInstance();
 
 const roleList = ref([]);
 const loading = ref(true);
 const showSearch = ref(true);
 const total = ref(0);
 const dateRange = ref([]);
 
 const data = reactive({
   form: {},
   queryParams: {
     current: 1,
     pageSize: 10,
     nickname: undefined,
     userID: undefined,
   },
   pageObj:{
    pageNumber: 1,
    showNumber: 10,
   },
   rules: {
     roleName: [{ required: true, message: "用户昵称不能为空", trigger: "blur" }],
     iphone: [{ required: true, message: "手机号不能为空", trigger: "blur" }],
     password: [{ required: true, message: "密码不能为空", trigger: "blur" }]
   },
 });
 
 const { queryParams, pageObj } = toRefs(data);
 
 /** 查询角色列表 */
 function getList() {
   loading.value = true;
   const parmas = {
    pagination: data.pageObj,
    ...data.queryParams
   }
   getUserList(parmas).then(response => {
     roleList.value = response.data.users;
     total.value = response.total;
     loading.value = false;
   });
 }
 
 /** 搜索按钮操作 */
 function handleQuery() {
   queryParams.value.pageNum = 1;
   getList();
 }
 
 /** 重置按钮操作 */
 function resetQuery() {
   dateRange.value = [];
   proxy.resetForm("queryRef");
   handleQuery();
 }

 /** 分配用户 */
 function handleRelation(row) {
   router.push({
    name: 'RelationList',
    params: { userID: row.userID }
   });
 }

 getList();
 </script>
<style scoped>
.upload_c{
    margin-bottom: 10px;
}
.upload_text{
    text-align: center;
    margin: 0 auto;
    margin-top: 10px;
    color: #1890ff;
    font-size: 14px;
}
.upload{
    width: 53px;
    height: 53px;
    border-radius: 10px;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #f5f5f5;
    margin: 0 auto;
}
</style>
 